package com.xiaoyu.client.adapter.mall;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xiaoyu.client.R;
import com.xiaoyu.client.model.goods.GoodsTagBean.GoodsTagParam;

import java.util.ArrayList;
import java.util.List;

public class GoodsTypeAdapter extends BaseAdapter {
    private Context mContext;
    private List<GoodsTagParam> mList = new ArrayList<>();
    private String index = "-1";

    public GoodsTypeAdapter(Context mContext, List<GoodsTagParam> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public GoodsTagParam getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder{
        TextView tagName;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_txt,null);
            holder = new ViewHolder();
            holder.tagName = convertView.findViewById(R.id.item_txt);

            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tagName.setText(getItem(position).getGoodstagname());
        if (getItem(position).getGoodstagid().equals(index)){
            holder.tagName.setTextColor(Color.parseColor("#eb3f3f"));
        }else {
            holder.tagName.setTextColor(Color.parseColor("#333333"));
        }
        return convertView;
    }

    public void updateList(List<GoodsTagParam> mList){
        this.mList = mList;
        this.notifyDataSetChanged();
    }

    public void setSelectId(String tagId){
        this.index = tagId;
        this.notifyDataSetChanged();
    }
}
